<template>
	<view>
		<cu-navbar :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">测试</block>
		</cu-navbar>

		<view v-if="test_type == 'mark'">
			<cu-mark :question="question" :title="title" :image="image" :test_num="test_num" :test_id="test_id"></cu-mark>
		</view>

		<view v-if="test_type == 'skip'">
			<cu-skip :question="question" :title="title" :image="image" :test_num="test_num" :test_id="test_id"></cu-skip>
		</view>

		<view v-if="test_type == 'component'">
			<cu-liang :question="question" :title="title" :image="image" :test_num="test_num" :test_id="test_id"></cu-liang>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			test_id: 0,
			title: '',
			image: '',
			test_num: 0,
			question: [],
			test_type: 'skip' //skip(跳转) , mark(打分)
		};
	},
	onLoad(e) {
		this.test_id = e.test_id;
		this.getstartTest();
	},
	methods: {
		getstartTest() {
			this.$api
				.startTest({
					test_id: this.test_id
				})
				.then(res => {
					if (res.code) {
						let question = res.data.question;
						question.sort(function(a, b) {
							return a['question_id'] - b['question_id'];
						});
						this.question = question;
						this.title = res.data.title;
						this.test_type = res.data.type;
						this.image = res.data.image;
						this.test_num = res.data.test_num;
					} else {
						this.$common.errorToShow(res.msg, () => {
							uni.navigateBack({
								delta: 1
							});
						});
					}
				});
		}
	}
};
</script>

<style>
page {
	background-color: #f4f6f8;
}
</style>
